package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseRepairTypeVo;
import com.manage.modules.bo.TBaseRepairTypeQueryBo;
import com.manage.modules.bo.TBaseRepairTypeAddBo;
import com.manage.modules.bo.TBaseRepairTypeEditBo;
import com.manage.modules.service.ITBaseRepairTypeService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 维修类型Controller
 *
 * @author wx
 * @date 2021-08-17
 */
@Api(value = "维修类型控制器", tags = {"维修类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/repairType")
public class TBaseRepairTypeController extends BaseController {

    private final ITBaseRepairTypeService iTBaseRepairTypeService;

    /**
     * 查询维修类型列表
     */
    @ApiOperation("查询维修类型列表")
    @PreAuthorize("@ss.hasPermi('modules:repairType:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseRepairTypeVo> list(TBaseRepairTypeQueryBo bo) {
        startPage();
        List<TBaseRepairTypeVo> list = iTBaseRepairTypeService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出维修类型列表
     */
    @ApiOperation("导出维修类型列表")
    @PreAuthorize("@ss.hasPermi('modules:repairType:export')")
    @Log(title = "维修类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseRepairTypeVo> export(TBaseRepairTypeQueryBo bo) {
        List<TBaseRepairTypeVo> list = iTBaseRepairTypeService.queryList(bo);
        ExcelUtil<TBaseRepairTypeVo> util = new ExcelUtil<TBaseRepairTypeVo>(TBaseRepairTypeVo.class);
        return util.exportExcel(list, "维修类型");
    }

    /**
     * 获取维修类型详细信息
     */
    @ApiOperation("获取维修类型详细信息")
    @PreAuthorize("@ss.hasPermi('modules:repairType:query')")
    @GetMapping("/{repairTypeId}")
    public AjaxResult<TBaseRepairTypeVo> getInfo(@PathVariable("repairTypeId") Long repairTypeId) {
        return AjaxResult.success(iTBaseRepairTypeService.queryById(repairTypeId));
    }

    /**
     * 新增维修类型
     */
    @ApiOperation("新增维修类型")
    @PreAuthorize("@ss.hasPermi('modules:repairType:add')")
    @Log(title = "维修类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseRepairTypeAddBo bo) {
        return toAjax(iTBaseRepairTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改维修类型
     */
    @ApiOperation("修改维修类型")
    @PreAuthorize("@ss.hasPermi('modules:repairType:edit')")
    @Log(title = "维修类型", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseRepairTypeEditBo bo) {
        return toAjax(iTBaseRepairTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除维修类型
     */
    @ApiOperation("删除维修类型")
    @PreAuthorize("@ss.hasPermi('modules:repairType:remove')")
    @Log(title = "维修类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repairTypeIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] repairTypeIds) {
        return toAjax(iTBaseRepairTypeService.deleteWithValidByIds(Arrays.asList(repairTypeIds), true) ? 1 : 0);
    }
}
